﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading.Tasks;
using RATSharp.Model;
using RATSharp.Rest;
using System.Runtime.Serialization;
using System.Windows.Data;
using RATSharpW7.Converters;

namespace RATSharpW7.ViewModel.CalendarViewModel
{
    [DataContract]
    public class DayViewObjectModel : AbstractDayViewModel
    {
        [DataMember]
        public int objectId { get; set; }
        [DataMember]
        public int userId { get; set; }
        public DayViewObjectModel(DateTime selDate, int objectId, int userId)
            : base(selDate)
        {
            this.objectId = objectId;
            this.userId = userId;
        }

        protected override Task<Reservations> getTask(DateTime firstDayInMonth, DateTime LastDayInMonth)
        {
            return RestService.getInstance().getReservationsObject(firstDayInMonth, LastDayInMonth, objectId);
        }

        protected override IDayViewColorProvider getColorProvider()
        {
            return new DayViewObjectColorProvider(userId);
        }

        public override bool isPeriodEditable(period period)
        {
            return period.FromDate.CompareTo(DateTime.Now) > 0;
        }
    }



      class DayViewObjectColorProvider : IDayViewColorProvider
    {

          int userId; 

          public DayViewObjectColorProvider(int userId)
          {
              this.userId = userId;
          }

        public SolidColorBrush provideColor(period period)
        {
            SolidColorBrush color;
            if (period.reservation.userId == userId)
            {

                color = new SolidColorBrush(Colors.Green);
            }
            else
            {
                color = new SolidColorBrush(Colors.Gray);
            }
            return color;
        }
}
  }